//
//  DDBaseWebViewController.m
//  DingDongZP
//
//  Created by Jyh on 16/5/23.
//  Copyright © 2016年 iyhjiang.com. All rights reserved.
//

#import "DDBaseWebViewController.h"

@interface DDBaseWebViewController ()
{
    UIActivityIndicatorView *activityIndicatorView;
}
@end

@implementation DDBaseWebViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self.view addSubview:self.webView];
    
    activityIndicatorView = [[UIActivityIndicatorView alloc]
                             initWithFrame : CGRectMake(0.0f, 0.0f, 32.0f, 32.0f)] ;
    [activityIndicatorView setCenter: self.view.center] ;
    [activityIndicatorView setActivityIndicatorViewStyle: UIActivityIndicatorViewStyleGray] ;
    [self.view addSubview : activityIndicatorView] ;
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (UIWebView *)webView
{
    if (!_webView) {
        
        CGRect webViewFrame = [[UIScreen mainScreen] applicationFrame];
        webViewFrame.origin.y = 0;
        webViewFrame.size.height -= CGRectGetHeight(self.navigationController.navigationBar.bounds);
        
        _webView = [[UIWebView alloc] initWithFrame:webViewFrame];
        [_webView sizeToFit];
        _webView.delegate = self;
        
        _webView.scalesPageToFit = YES;
    }
    
    return _webView;
}

- (void)loadDataWithURLString:(NSString *)urlString
{
    [self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:urlString]]];
}

- (void)webViewDidStartLoad:(UIWebView *)webView
{
    [activityIndicatorView startAnimating] ;
}

- (void)webViewDidFinishLoad:(UIWebView *)webView
{
    [activityIndicatorView stopAnimating];
}

- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error
{
    [activityIndicatorView stopAnimating];
}


@end
